import java.util.*;

/**
 * @author LKQ
 * @date 2022/5/24 20:34
 * @description 贪心
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int maximumBags(int[] capacity, int[] rocks, int additionalRocks) {
        int n = capacity.length;
        for (int i = 0; i < n; i++) {
            capacity[i] -= rocks[i];
        }
        Arrays.sort(capacity);
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (additionalRocks >= capacity[i]) {
                additionalRocks -= capacity[i];
                ans = i + 1;
            }else {
                break;
            }
        }
        return ans;
    }
}
